package com.hra.logger.collector;

import android.util.Log;

import com.hra.logger.utils.Utils;

import java.util.ArrayList;
import java.util.List;

public class KernelLogCollector extends BaseLogCollector {
    private final List<BaseLogCollector> subCollectors = new ArrayList<>();

    public KernelLogCollector() {
        super(Utils.LOG_TYPE_NAME_KERNEL, "", "");

        addSubCollector("kernel", "logcat -b kernel -v threadtime");
        addSubCollector("dmesg", "dmesg");
        addSubCollector("kmsg", "cat /proc/kmsg");
    }

    private void addSubCollector(String subName, String logCommand) {
        subCollectors.add(new BaseLogCollector(Utils.LOG_TYPE_NAME_KERNEL, subName, logCommand));
    }

    @Override
    public void start() {
        if (Utils.DEBUG) {
            Log.d(TAG, "Starting KernelLogCollector with all sub-collectors");
        }
        for (BaseLogCollector collector : subCollectors) {
            collector.start();
        }
    }

    @Override
    public void stop() {
        if (Utils.DEBUG) {
            Log.d(TAG, "Stopping KernelLogCollector with all sub-collectors");
        }
        for (BaseLogCollector collector : subCollectors) {
            collector.stop();
        }
    }

    @Override
    public void setFirstStartAfterReboot(boolean firstStartAfterReboot) {
        super.setFirstStartAfterReboot(firstStartAfterReboot);
        for (BaseLogCollector collector : subCollectors) {
            collector.setFirstStartAfterReboot(firstStartAfterReboot);
        }
    }

    @Override
    public boolean isVisible() {
        return true;
    }
}
